package com.bandroid.demo.view;

import android.os.Bundle;

import com.bandroid.demo.base.MyActivity;

import java.lang.reflect.Constructor;

import IPlugin.IPlugin;
import dalvik.system.DexClassLoader;

/**
 * BAndroid
 * Created by YichenZ on 2016/2/16 10:51.
 */
public class PluginActivity extends MyActivity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //demoPluginImpl
        try{
            String dexOutputDir = getApplicationInfo().dataDir;
            ClassLoader classLoader =getClassLoader();
            DexClassLoader localDexClassLoader =new DexClassLoader("/sdcard/app-debug.apk",dexOutputDir,null,classLoader);

            Class localClass =localDexClassLoader.loadClass("plugin.yc.org.demoplu.PluginImpl");
            Constructor localConstructor = localClass.getConstructor(new Class[]{});
            Object instance =localConstructor.newInstance(new Object[]{});

            IPlugin iPlugin =(IPlugin)instance;
            System.out.println(iPlugin.getName());
            iPlugin.show();
        }catch (Exception e){

        }
    }
}

